/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package cn.edu.ntu.yyl.service.imlp;

import cn.edu.ntu.yyl.dao.ArticleCategoryDao;
import cn.edu.ntu.yyl.dao.ArticleDao;
import cn.edu.ntu.yyl.dao.UserInfoDao;
import cn.edu.ntu.yyl.pojo.article.Article;
import cn.edu.ntu.yyl.pojo.article.ArticleCategory;
import cn.edu.ntu.yyl.vo.ArticleVO;
import cn.edu.ntu.yyl.pojo.user.UserInfo;
import cn.edu.ntu.yyl.service.ArticleShowService;
import cn.edu.ntu.yyl.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class ArticleShowServiceImpl implements ArticleShowService {
    @Autowired
    private UserInfoDao userInfoDao;
    @Autowired
    private ArticleCategoryDao articleCategoryDao;
    @Autowired
    ArticleDao articleDao;

    public List<ArticleVO> Show(List<Article> articleList){
        List<ArticleVO> articleVOList = new ArrayList<>();
        for (Article article:articleList) {
            ArticleVO articleVO = Show(article);
            articleVOList.add(articleVO);
        }
        return articleVOList;
    }

    public ArticleVO Show(Article article){
        ArticleVO articleVO = new ArticleVO();
        UserInfo userInfo = userInfoDao.SelectUserByArticle(article);
        ArticleCategory classify = articleCategoryDao.SelectCategoryByArticle(article);
        List<ArticleCategory> tags = articleCategoryDao.SelectTagByArticle(article);
        articleVO.setArticle(article);
        articleVO.setClassify(classify);
        articleVO.setTags(tags);
        articleVO.setUserInfo(userInfo);
        return articleVO;
    }

    //更新文章
    @Override
    public Integer UpdateArticleVO(ArticleVO articleVO) {
        Article article = articleVO.getArticle();
        List<ArticleCategory> tags = articleVO.getTags();
        ArticleCategory classifys = articleVO.getClassify();
        UserInfo user = articleVO.getUserInfo();
        article.setUser_id(user.getId());

        return null;
    }
    //新建文章
    @Override
    public Integer AddArticleVO(ArticleVO articleVO) {
        return null;
    }
}
